<template>
    <div class="layout-route" style="position: relative; padding-top: 32px;" v-loading="loading">
        <div style="position: absolute;height: 32px; top: 0; left: 20px">
            <el-button type="text" icon="el-icon-arrow-left" @click="goBack()">返回</el-button>
        </div>
        <div class="detail-card">
            <div class="detail-head">
                <div class="detail-head-avatar">
                    <img :src="person_info.head_url" alt=""  v-if="person_info.head_url"/>
                </div>
                <div class="detail-head-info">
                    <div class="detail-head-name">{{ person_info.expert_name }}</div>
                    <div class="detail-head-id">ID: {{ person_info.expert_id }}</div>
                </div>
                <div class="detail-head-platform">
                    <el-image
                        v-for="(item, index) in platformIdList"
                        :key="index"
                        style="width: 50px; cursor: pointer; margin-right: 4px"
                        :src="item | formatLabelByValueFuzzy(platformType, { label: 'icon' })"
                        :title="`进入${platformTitle(item)}官方平台达人主页`"
                        @click="toNewPage(linkList[index])"
                    ></el-image>
                </div>
            </div>
            <div class="detail-base">
                <div class="detail-row">
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">负责人：</div>
                        <div class="detail-base-item-content">{{ person_info.operater }}</div>
                    </div>
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">邮箱：</div>
                        <div class="detail-base-item-content">
                            <el-link type="primary" target="_blank">{{ person_info.email }}</el-link>
                        </div>
                    </div>
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">电话：</div>
                        <div class="detail-base-item-content">{{ person_info.kol_phone }}</div>
                    </div>
                </div>
                <div class="detail-row">
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">合作店铺：</div>
                        <div class="detail-base-item-content">{{ person_info.shop_name }}</div>
                    </div>
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">合作价格：</div>
                        <div class="detail-base-item-content">{{ person_info.cooperate_price }}</div>
                    </div>
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">合作记录：</div>
                        <div class="detail-base-item-content">{{ person_info.cooperate_nums }}次</div>
                    </div>
                </div>
                <div class="detail-row">
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">品类：</div>
                        <div class="detail-base-item-content">{{ person_info.cooperate_spu }}</div>
                    </div>
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">标签：</div>
                        <div class="detail-base-item-content">
                            <template v-if="person_info.tags">
                                <el-tag size="mini" v-for="tag in tags" :key="tag" style="margin-right: 4px">{{ tag }}</el-tag>
                            </template>
                        </div>
                    </div>
                    <div class="detail-base-item">
                        <div class="detail-base-item-title">级别：</div>
                        <div class="detail-base-item-content">
                            <template v-if="person_info.level > 0">
                                <el-tag size="mini" type="danger">{{ person_info.level | formatLabelByValueFuzzy(COOPERATION_LEVEL) }}</el-tag>
                            </template>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="detail-card">
            <div class="detail-title">达人素材</div>
            <div class="video-container">
                <!-- <button class="scroll-button left" @click="scrollVideos('left')">
                    <i class="el-icon-arrow-left"></i>
                </button> -->
                <div class="detail-videos detail-base" ref="videoList">
                    <div class="detail-video" v-for="item in video_info" :key="item.id">
                        <video :src="item" autoplay muted controls></video>
                    </div>
                </div>
                <!-- <button class="scroll-button right" @click="scrollVideos('right')">
                    <i class="el-icon-arrow-right"></i>
                </button> -->
            </div>
        </div>
    </div>
</template>

<script>
import { getPersonList } from '@/api/expert'
import InstagramEmbed from 'vue-instagram-embed'
import { PLATFORM_TYPE, COOPERATION_LEVEL } from '../constant'
export default {
    name: 'ExpertDetail',
    components: {
        InstagramEmbed,
    },
    data() {
        return {
            person_info: {},
            video_info: [],
            loading: false,
            siteList: [],
            COOPERATION_LEVEL,
            platformType: PLATFORM_TYPE,
        }
    },
    computed: {
        tags() {
            return this.person_info.tags?.split(',')?.filter(item => !!item) ?? []
        },
        linkList() {
            return this.person_info.link ? JSON.parse(this.person_info.link || '[]') : []
        },
        platformIdList() {
            return this.person_info.platform_id?.split(',')?.filter(item => !!item) ?? []
        },
    },
    created() {
        this.getDetail()
    },
    methods: {
                goBack() {
            this.$router.go(-1)
            
        },
        platformTitle(id) {
            return this.platformType.find(item => item.value == id)?.label
        },
        toNewPage(url) {
            window.open(url, '_blank')
        },
        getDetail() {
            this.loading = true
            getPersonList({ expert_id: this.$route.query.expert_id })
                .then(res => {
                    this.person_info = res.data.person_info
                    this.video_info = res.data.video_info
                })
                .finally(() => {
                    this.loading = false
                })
        },
        scrollVideos(direction) {
            const videoList = this.$refs.videoList;
            const scrollAmount = 300; // 每次滚动的像素值
            if (direction === 'left') {
                videoList.scrollLeft -= scrollAmount;
            } else {
                videoList.scrollLeft += scrollAmount;
            }
        },
    },
}
</script>

<style lang="scss" scoped>
.detail-card {
    border-radius: 0.5rem;
    background-color: #fff;
    box-shadow: 0 1px 2px rgba(214, 219, 226, 0.5), 0 1px 2px rgba(214, 219, 226, 0.5);
    margin-bottom: 24px;
    padding: 1.75rem;
    font-size: 1rem;
}
.detail-head {
    display: flex;
    align-items: center;
}
.detail-head-avatar {
    border-radius: 50%;
    width: 5.625rem;
    height: 5.625rem;
    margin-right: 1.25rem;
    background-color: #c5c9d1;
    img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
    }
}
.detail-head-name {
    display: flex;
    -webkit-box-align: center;
    align-items: center;
    flex-direction: row;
    gap: 0.5rem;
    font-weight: 600;
    line-height: 1.5;
}
.detail-head-id {
    display: flex;
    -webkit-box-align: center;
    align-items: center;
    flex-direction: row;
    line-height: 1.5;
}
.detail-head-platform {
    display: flex;
    margin-left: 3.75rem;
}
.detail-title {
    font-weight: 600;
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
}
.detail-base {
    margin-top: 1.75rem;
    padding: 1.25rem;
    background: rgb(249, 250, 252);
    border-radius: 0.5rem;
    font-size: 12px;
    .detail-row {
        display: flex;
        -webkit-box-align: baseline;
        align-items: baseline;
        flex-direction: row;
        // gap: 5.5rem; 
        & + .detail-row {
            margin-top: 0.687rem;
            gap: 0.687rem 0;
        }
    }
    .detail-base-item {
        display: flex;
        align-items: center;
        flex: 1;
        // & + .detail-base-item {
        //     margin-left: 0.5rem;
        // }
        .detail-base-item-title {
            font-weight: normal;
            color: #666;
        }
        .detail-base-item-content {
            color: #1a202c;
            font-weight: normal;
            padding-left: 4px;
        }
    }
}
.detail-videos {
    display: flex;
    // overflow-x: auto;
    // scroll-behavior: smooth;
    // scrollbar-width: none;
    width: 100%;
    flex-wrap: wrap;
    &::-webkit-scrollbar {
        display: none;
    }
    .detail-video {
        width: calc(25% - 6px);
        margin: 0 8px 4px 0;
        &:nth-child(4n) {
            margin-right: 0;
        }
        video {
            width: 100%;
            height: 240px;
        }
    }
}
.video-container {
    position: relative;
    display: flex;
    align-items: center;
    &:hover .scroll-button {
        opacity: 1;
    }
}
.scroll-button {
    position: absolute;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.scroll-button.left {
    left: 0;
}
.scroll-button.right {
    right: 0;
}
</style>
